#include "igs_adc.h"

#define NUM_OF_BATTERY 1

struct battery_device_t
{
	uint8_t IsEnable;
}battery_device[NUM_OF_BATTERY];

static void adc_polling(void);
static void battery_command(uint8_t *buf, uint32_t len);

static uint8_t command[8];

/**
 *  @brief igs_adc_init
 */
void igs_adc_init(void)
{
	igs_task_add(IGS_TASK_ROUTINE_POLLING, 5000,adc_polling);
	igs_protocol_command_register(COMMAND_BATTERY,battery_command);
}

/**
 *  @brief adc_polling
 */
static void adc_polling(void)
{
	uint32_t i;
	for(i=0;i<NUM_OF_BATTERY;i++)
	{
		if(battery_device[i].IsEnable == 1)
		{
			
			command[0] = COMMAND_BATTERY;
			command[1] = 3;
			command[2] = COMMAND_BATTERY_RET;
			command[3] = i;
			command[4] = 0xFF;

			igs_queue_push(IGS_QUEUE_TX_TYPE,command,5);
		}
	}
}

/**
 *  @brief battery_command
 */
static void battery_command(uint8_t *buf, uint32_t len)
{
	uint8_t id;
	uint8_t IsEnable;
	switch(buf[0])
	{
		case COMMAND_BATTERY_INIT:
			if(id < NUM_OF_BATTERY)
			{
				battery_device[id].IsEnable = IsEnable;
			}
			break;
		default:;
	}

}
